<?php

if (!defined('IN_ADMIN')) {
    exit('Access Denied');
}

$mpurl = 'admin.php?ac=user';
$list = array();
if ($_GET ['op'] == "chain") {
    // 封禁&解禁
    $uid    = intval($_GET ['uid']);
    $status = intval($_GET ['status']);
    $forbid = intval($_GET ['forbid']);

    $param = array(
        'do'           =>    'chainUser',
        'format'       =>    'json',
        'uid'          =>    $uid,
        'status'       =>    $status,
        'forbidDevice' =>    $forbid,
    );

    $content = get_api_content($_SC ['apiurl'], $param);
    $content = json_decode($content);
    if ($content->resultData == 1) {
        $msg = "操作成功!";
        cpmessage($msg);
    }
    $msg = "操作失败，请重试一次!";
    if ($content->errorNo) {
        $msg .= "errorNo:" . $content->errorNo;
    }
    cpmessage($msg);
}elseif($_GET['op']=='getConnent'){
    //获取用户第三方绑定信息
    $uid=intval($_GET['uid']);
    $param=array(
        'do'=>"getConnent",
        'action'=>"getConnent",
        'format'=>'json',
        'uid'=>$uid
    );
    $result=get_api_content($_SC['apiurl'],$param);
    $result=json_decode($result);
    $result=object_to_array($result->resultData);
    include_once template("admin_v2/".'connent');
    exit;
} elseif($_GET['op']=="accountUnbind"){
    //删除所选绑定信息
    $uid=intval($_GET['uid']);
    $type=$_GET['type'];
    $param=array(
        'do'=>'user',
        'action'=>'accountUnbindfromadmin',
        'format'=>'json',
        'uid'=>$uid,
        'type'=>$type,
     );
    $content=get_api_content($_SC['apurl'],$param);
    $content = json_decode($content);
    if ($content->resultData ==true) {
        $msg = "操作成功!";
        cpmessage($msg);
    }
    $msg = "操作失败，请重试一次!";
    if ($content->errorNo) {
        $msg .= "errorNo:" . $content->errorNo;
    }
    cpmessage($msg);


}elseif($_GET ['op'] == "loginout"){
	unset ( $_SESSION ["user"] );
	clearcookie ();
	ssetcookie ( '_refer', '' );
	include_once template("admin/".'login');
	exit;
}elseif($_GET ['op'] == "removeUser"){
	$uid    =    $_GET['uid'];
    $param = array(
            'do' => 'removeUser',
            'format' => 'json',
            'uid' => $uid,
    );
    $content = get_api_content($_SC ['apiurl'], $param);
//     echo $content;exit;
    $content = json_decode($content);
    echo $content->resultData;
	exit;
}elseif($_GET ['op'] == "actionManage"){
    $uid    =    $_GET['uid'];
    $action =    $_GET['action'];
    $time   =    $_GET['time'];
    $param = array(
            'do' => $action,
            'format' => 'json',
            'uid' => $uid,
            'time' => $time,
    );
    $content = get_api_content($_SC ['apiurl'], $param);
//     echo $content;exit;
    $content = json_decode($content);
    if ($content->resultData == 1) {
        $msg = "操作成功!";
        cpmessage($msg);
    }
    $msg = "操作失败，请重试一次!";
    if ($content->errorNo) {
        $msg .= "errorNo:" . $content->errorNo;
    }
    cpmessage($msg);
	exit;
} else {

    // 列表
    $start = intval($_GET ['start']);
    // 参数过滤解析
    $perpage = intval($_GET ['perpage']) > 0 ? intval($_GET ['perpage']) : 20;

    // 搜索条件
    $intkeys = array(
        'uid'
    );
    $strkeys = array(
        'nickname',
        'account',
        'email',
        'deviceSN'
    );
    $results = getparam($intkeys, $strkeys);
    $mpurl .= '&' . implode('&', $results ['urls']);

    // 构建api请求url与参数数组
    $param = array(
        'do' => 'fetchUserInfo',
        'format' => 'json',
        'start' => $start,
        'length' => $perpage,
    );
    $param = array_merge($param, $results ['param']);
    
    // 读取api数据
    $content = get_api_content($_SC ['apiurl'], $param);
    $content = json_decode($content);
    if ($content->resultData) {
        $list = object_to_array($content->resultData);
    }

    // page
    $pageurl = multi($start, $perpage, $mpurl);
    $nextpurl = $pageurl ['next'];
    $prevpurl = $pageurl ['prev'];
    $mpurl = $pageurl ['urls'];
    $firstpurl = $pageurl ['first'];

    $perpages = array(
        $perpage => ' selected'
    );
}




